﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ResourceFileMgr.aspx.cs"
    Inherits="SkWeb.SystemManage.ResourceFileMgr" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>资源文件管理</title>
    <link href="../easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <script src="../easyui/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../js/jquery.uploadify-v2.1.0/swfobject.js" type="text/javascript"></script>
    <script src="../js/jquery.uploadify-v2.1.0/jquery.uploadify.v2.1.0.min.js" type="text/javascript"></script>
    <link href="../js/jquery.uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        function deleteTemplate(id) {
            $.messager.confirm("提示框", "您确认要删除吗？", function (r) {
                if (r) {
                    $.post('../Handlers/OperateHandler.aspx?op=deleteresourcefile',
                    {
                        tmpid: id
                    }, function (data) {
                        if (data.success) {
                            $.messager.alert("提示框", "删除成功");
                            $("#divResourceFile").treegrid("reload");
                        }
                        else {
                            $.messager.alert("提示框", data.msg);
                        }

                    });
                }
            });
        }

        function addTemplate(fid, typecode) {
            $('#hidefid').val(fid);
            
            if (typecode == 20) {
                $("#addcatalogdiv").dialog("open");
            }
            else {
                $("#adddiv").window("open");
            }


        }

        $(function () {

            // ***************************** 添加文件夹 *************************************

            $("#btnAddCatalog").click(function () {
                $.post('../Handlers/OperateHandler.aspx?op=addresourcecatalog', {
                    fid: $('#hidefid').val(),
                    cataname: $("#txtCatalogName").val()
                }, function (data, statusText) {
                    if (data.success) {
                        $.messager.alert("提示框", "添加成功！");
                        $("#addcatalogdiv").dialog("close");
                        $("#divResourceFile").treegrid("reload");
                    }
                    else {
                        $.messager.alert("提示框", data.msg);
                    }
                });
            });

            // ***************************** 文件上传 ***************************************
            $("#uploadify").uploadify({
                'uploader': '../js/jquery.uploadify-v2.1.0/uploadify.swf',
                'script': '../Handlers/OperateHandler.aspx?op=addresourcefile',
                'cancelImg': '../js/jquery.uploadify-v2.1.0/cancel.png',
                'auto': true,
                'multi': false,
                'onSelect': function (e, queneID, fileObj) {
                    $("#uploadify").uploadifySettings('scriptData', {
                        'fid': $('#hidefid').val()
                    });
                },
                'onComplete': function (e, queneID, fileObj) {
                    $("#divResourceFile").treegrid("reload");
                }
            });



            $("#divResourceFile").treegrid({
                url: '../Handlers/SchemeDesignHandler.aspx?op=gettemplatetree&pid=1100',
                idField: 'TMP_ID',
                treeField: 'TMP_MC',
                columns: [[
                    { title: '模版分类', field: 'TMP_MC', width: 480 },
                    {
                        title: '操作', field: 'TMP_URL',
                        formatter: function (value, rowData, rowIndex) {
                            if (rowData.TYP_CODE == 30) {
                                return "<a href='" + value + "' >下载</a> &nbsp; <a href='#' onclick='deleteTemplate(" + rowData.TMP_ID + ");' >删除</a>";
                            }
                            else {
                                return "<a href='#' onclick='addTemplate(" + rowData.TMP_ID + ", 20);' >添加子文件夹</a> &nbsp; <a href='#' onclick='addTemplate(" + rowData.TMP_ID + ", 30);' >添加子文件</a> &nbsp; <a href='#' onclick='deleteTemplate(" + rowData.TMP_ID + ");' >删除</a>";
                            }
                        }
                    }
                ]]
            });
        });
    </script>
    <style type="text/css">
        .condTable
        {
            border: solid 1px #718BB7;
            padding: 0;
            letter-spacing: 0;
            font-size: 12px;
            text-align: left;
            margin-top: 5px;
            margin-bottom: 5px;
            border-collapse: collapse;
            border-spacing: 0;
        }
        .condTable td
        {
            border: solid #B4C9C6 1px;
            border-collapse: separate;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divResourceFile">
    </div>
    <div id="adddiv" class="easyui-window" data-options="closed:true" title="文件上传" style="width: 500px;
        height: 350px; padding: 10px 10px 10px 10px">
        <input type="file" name="uploadify" id="uploadify" >
        <input type="hidden" id="hidefid">
    </div>
    <div id="addcatalogdiv" class="easyui-dialog" data-options="closed:true, buttons:'#dialogColumnParams-buttons'" title="添加文件夹"
        style="width: 400px; height: 300px;">
        <table class="condTable" width="100%">
            <tr>
                <td>
                    文件夹名称
                </td>
                <td>
                    <input type="text" id="txtCatalogName" class="easyui-validatebox" data-options="required:true, prompt:'请输入文件夹名称'">
                </td>
            </tr>
        </table>
    </div>
    <div id="dialogColumnParams-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddCatalog" >提交</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#addcatalogdiv').dialog('close')">关闭</a>
    </div>
    </form>
</body>
</html>
